package cn.controller;

import cn.entity.Result;
import cn.entity.SysArea;
import cn.entity.SysUser;
import cn.service.SysAreaSerevice;
import cn.service.SysUserService;
import cn.utils.EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

@RestController
@RequestMapping("/sysuser")
public class SysUserController {
    @Autowired
    SysUserService sysUserService;

    @RequestMapping("")
    public ModelAndView user(){
        return new ModelAndView("user/user");
    }

    @RequestMapping("detail")
    public ModelAndView detail(){
        return new ModelAndView("user/user-detail");
    }

    @RequestMapping("update")
    public ModelAndView update(){
        return new ModelAndView("user/detail");
    }
    @RequestMapping("index/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum")int pageNum, @PathVariable("pageSize")int pageSize, @RequestBody HashMap<String,Object> map){
        return new Result(true,"成功",sysUserService.selectPage(pageNum,pageSize,map));
    }

    @RequestMapping("/deleteOne")
    public Result deleteOne(@RequestBody SysUser sysUser){
        sysUser.setDelFlag("1");
        sysUser.setUpdateDate(new Date());
        return new Result(true,"删除成功",sysUserService.updateByPrimaryKeySelective(sysUser));
    }

    @RequestMapping("/doUpdate")
    public Result doUpdate(@RequestBody SysUser sysUser){
        sysUser.setUpdateDate(new Date());
        return new Result(true,"删除成功",sysUserService.updateByPrimaryKeySelective(sysUser));
    }


    @RequestMapping("/saveOne")
    public Result saveOne(@RequestBody SysUser newUser){
        String password = newUser.getPassword();
//        newUser.setPassword(EncryptUtils.MD5_HEX(EncryptUtils.MD5_HEX(password)+username));
//        return new Result(true,"删除成功",sysUserService.updateByPrimaryKeySelective(newUser));
        return null;
    }
}
